package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.PmsSkuStockMapper;
import com.mall.domain.PmsSkuStock;
import com.mall.interface1.api.PmsSkuStockApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsSkuStockApiImpl implements PmsSkuStockApi {

    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;

    //根据商品ID及sku编码模糊搜索sku库存
    public List<PmsSkuStock> searchSku(Long pid, String keyword) {
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(pid != null,PmsSkuStock::getProductId,pid);
        queryWrapper.like(keyword != null,PmsSkuStock::getSkuCode,keyword);
        return pmsSkuStockMapper.selectList(queryWrapper);
    }

    //更新sku库存信息
    public void updateSku(Long pid, PmsSkuStock pmsSkuStock) {
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(pid != null,PmsSkuStock::getProductId,pid);
        pmsSkuStockMapper.update(pmsSkuStock,queryWrapper);
    }


}
